package com.zhuoyue.common.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * @ClassName: Time
 * @Description:
 * @author wjming
 * @Date 2021-07-14 20:06
 */
public class Time {
    /**
     * 时间转化为时间戳毫秒
     */
    public static Long toLongMilli(LocalDateTime localDateTime) {
        if (localDateTime != null) {
            return localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        } else {
            return null;
        }
    }

    public static Long toGetNowLongSecond() {
        return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
    }

    public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
        Instant instant = Instant.ofEpochMilli(timestamp);
        ZoneId zone = ZoneId.systemDefault();
        return LocalDateTime.ofInstant(instant, zone);
    }

}
